import config from './config';
let VUE_APP_API_URL = config.VUE_APP_API_URL;

// #ifdef H5
if(process.env.NODE_ENV === 'development'){
    console.log('开发环境')
}else{
    console.log('生产环境');
	VUE_APP_API_URL = '/api';
}
// #endif

class Http {
  request(type, uri, para) {
	 console.log('request =======', VUE_APP_API_URL)
    let root = this;
	if (!para) para = {};
	const uuid = uni.getStorageSync('uuid') || false;
	if (uuid) para['uuid'] = uuid;
    let promise = new Promise(function (resolve, reject) {
      uni.request({
        url: `${VUE_APP_API_URL}/${uri}`,
        data: para,
        header: {},
        dataType: 'json',
        method: type,
        success: function (res) {
          resolve(res.data);
        },
        fail: function (res) {
			console.log('fail',fail)
		}
      })
    })
    return promise;
  }
  get(url, para) {
    return this.request('get', url, para);
  }
  put(url, para) {
    return this.request('put', url, para);
  }
  post(url, para) {
    return this.request('post', url, para);
  }
  delete(url, para) {
    return this.request('delete', url, para);
  }
}

export default new Http();